import App from './App'
import { createSSRApp } from 'vue'
import store from './store'
import bootstrap from './core/bootstrap'
import mixin from './core/mixins/app'
import uView from './uni_modules/vk-uview-ui'
import { navTo, showToast, showSuccess, showError, getShareUrlParams, checkModuleKey, checkModules } from './core/app'
import AddDeviceService from '@/service/AddDeviceService'
import StorageUtils from './utils/StorageUtils'
import CacheConfig from './config/CacheConfig'
import Tabbar from '@/components/tabbar/index.vue'

// 不能修改createApp方法名，不能修改从Vue中导入的createSSRApp
export function createApp() {
  // 创建应用实例
  const app = createSSRApp({ ...App, store, created: bootstrap })

  // 挂载全局函数
  app.config.globalProperties.$toast = showToast
  app.config.globalProperties.$success = showSuccess
  app.config.globalProperties.$error = showError
  app.config.globalProperties.$navTo = navTo
  app.config.globalProperties.$getShareUrlParams = getShareUrlParams
  app.config.globalProperties.$checkModule = checkModuleKey
  app.config.globalProperties.$checkModules = checkModules
  app.config.globalProperties.$addDeviceService = AddDeviceService
  app.config.globalProperties.$isLogin = function() {
	const userInfo = StorageUtils.get(CacheConfig.USER_INFO_KEY)
	if(!userInfo) {
		uni.navigateTo({
			url:'/pages/mine/authorize'
		})
	}
	return !!userInfo;
  }
  // 图片远程地址
	app.config.globalProperties.$IMAGE_BASE_URL = "https://mircostone.oss-cn-hangzhou.aliyuncs.com/taideng";
	app.config.globalProperties.$IMAGE_BASE_URL2 = "https://mircostone.oss-cn-hangzhou.aliyuncs.com";
	app.config.globalProperties.$IMAGE_BASE_URL3 = "https://mircostone.oss-cn-hangzhou.aliyuncs.com/yangcan";
  app.component('Tabbar', Tabbar);
  // 使用 uView UI
  app.use(uView)

  // 全局mixin
  app.mixin(mixin)

  return { app }
}